package cate.game.play.skill.passive.fairy;

import cate.common.table.d.GDAttr;
import cate.common.table.d.GDSkill;
import cate.game.play.base.TargetFilterParam;
import cate.game.play.base.TargetSelector;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.ActionCtx;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.skill.passive.PassiveHandler;

import java.util.List;

/**
 *
 * "圣光指引"释放时 如果自身为全队血量最低则额外给自身80%攻击的护盾,并提升自身10%的伤害减
 *
 * 战斗开始前为自身和攻击最高的2个单位附加【圣甲】,不可驱散！受致死伤害时强制血量为1,
 */
public class 至尊帝王蟹灵器PH extends PassiveHandler {

	private String 技能标签;
	private int 护盾buff;
	private int 免伤buff;

	private int 队友人数;
	private int buff;

	//技能标签=圣光指引&护盾buff=？？&免伤buff=？？&
	//队友人数=2&buff=？？
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		技能标签 = args.get("技能标签");
		护盾buff = args.getInt("护盾buff", 0);
		免伤buff = args.getInt("免伤buff", 0);
		队友人数 = args.getInt("队友人数", 0);
		buff = args.getInt("buff", 0);
	}

	@Override
	public void onSkillDone(SkillActionCtx action) {
		if(!action.getSkill().cfg.containTag(技能标签)){
			return;
		}
		TargetFilterParam filterParam = new TargetFilterParam();
		filterParam.scopeSet(GDSkill.Scope.WE).smallAttrSet(GDAttr.V_HP_LEFT_RATE);

		Fighter target = TargetSelector.findOne(skill.owner, action.getTeamVs(), filterParam);
		if (target != null && target.getPid() == skill.owner.getPid()) {
			target.buff.tryAddByTid(action, skill.owner, 护盾buff);
			target.buff.tryAddByTid(action, 免伤buff);
		}
	}


	@Override
	public void onFirstEnter(ActionCtx action) {
		TargetFilterParam param = new TargetFilterParam().scopeSet(GDSkill.Scope.FRIENDS).bigAttrSet(GDAttr.ATT).targetNumSet(队友人数);
		List<Fighter> fighters = TargetSelector.doFind(skill.owner, action.getTeamVs(), param);
		fighters.add(skill.owner);
		for (Fighter target : fighters) {
			target.buff.tryAddByTid(action, buff);
		}
	}
}
